<template>
  <div class="dynamicBox">
    <div>
      <h4 style="margin:0 0 10px 0"> 动态评价 </h4>
      <!-- <el-row style="margin-bottom:10px;display:flex;align-items:center">
        <el-col :span="8" >
        </el-col>
        <el-col :span="16" style="text-align:right">
          <el-input v-model="sheachValue" style="width:300px" placeholder="输入搜索内容"></el-input>
          <el-button type="primary" @click="seachFun">搜索</el-button>
        </el-col>
      </el-row> -->
      
      <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column prop="name" label="序号" width="60">
          <template slot-scope="scope">{{scope.$index+1}}</template>
        </el-table-column>
      <el-table-column prop="dynamicUser.userNick" label="id" width="80"> </el-table-column>
      <el-table-column prop="product.title" label="商品"  width="140"> </el-table-column>
      <el-table-column prop="address" label="评论内容">
        <template slot-scope="scope">
          <div >
            <div class="colorOne" style="margin-bottom:5px">
              <span style="padding-right:30px">评分：{{scope.row.totalscore}}</span>
              <span style="padding-right:30px">环境：{{scope.row.ambienceScore }}</span>
              <span style="padding-right:30px">专业：{{scope.row.serviceScore}}</span>
              <span style="padding-right:30px">效果：{{scope.row.effectScore}}</span>
            </div>
            <div>{{scope.row.dynamicContent}}</div>
            <div>
              <img v-for="(item,index)  in scope.row.images" :src="srcFun(item.imageUrl)" :key="index" @click="showImage(srcFun(item.imageUrl))" style="margin-right:5px;width:70px;height:80px"/>
            </div>
            <el-row style="text-align:right">
              <el-col :span="12" style="text-align:left">{{timeFun(scope.row.createtime)}}</el-col>
              <el-col :span="4" class="colorOne">转发：{{scope.row.shares}}</el-col>
              <el-col :span="4" class="colorOne">喜欢：{{scope.row.countLike}}</el-col>
              <el-col :span="4" class="colorOne">评论：{{scope.row.countComment}}</el-col>
            </el-row>
          </div>
        </template>
      </el-table-column>      
      <!-- <el-table-column prop="status" label="状态" width="80">
        <template slot-scope="scope">
          
          <span style="color:#333" v-if="scope.row.dynamicStatus == 0" type="info">未审核</span>
          <span style="color:#67c23a" v-if="scope.row.dynamicStatus == 1"  type="success">通过</span>
          <span style="color:#f56c6c" v-if="scope.row.dynamicStatus == 2"  type="danger">删除</span>
          <div style="color:red" v-if="scope.row.orderAt">置顶</div>

        </template>
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <div>
           
            <el-button   type="primary" class="addBtn" @click="stickFun(scope)">置顶</el-button>
            <el-button   class="addBtn" @click="upStickFun(scope)">取消置顶</el-button>
            <el-button  type="success" class="addBtn" @click="passFun(scope,1)">通过</el-button>
            <el-button  class="addBtn" type="danger"  @click="passFun(scope,2)"> 删除</el-button>
            <el-button  type="success" class="addBtn" @click="passFun(scope,1)">恢复</el-button>

          </div>
        </template>
      </el-table-column> -->
    </el-table>
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="imgstuts">
      <img width="100%" :src="titleImgurl" alt="">
    </el-dialog>
     
     <el-dialog :title="title" :visible.sync="dialogVisible" center width="40%" :before-close="handleClose">
        <el-form label-position="left" label-width="80px" ref="ruleForm2" :model="ruleForm2" :rules="rules2">
          <el-form-item label="标签名：" prop="labelName">
            <div style="display:flex;align-items:center">
              <el-input v-model="ruleForm2.labelName" style="width:300px"></el-input>
            </div>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="submitFun('ruleForm2')">确 定</el-button>
        </span>
      </el-dialog>
     
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage4"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'

  export default {
    data() { 
     
      var labelName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('请输入标签名'));
        } else {
          callback();
        }
      };
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        currentPage4: 1,//分野  
        total:0,      
        tableData: [],
        page:1,
        dialogVisible: false,
        imgstuts:false,
        titleImgurl:'',
        editId:'',
        title:'添加标签',
        pageSize:10,
        sheachValue:'',
        totalscore:'', //评分
        ambienceScore:'', //环境
        effectScore:'', //专业
        serviceScore:'', //服务
        formLabelAlign: {
          name: '',
          region: '',
          type: ''
        },
        ruleForm2: {
          labelName: '',
        },
        rules2: {
          labelName:[
             { validator: labelName, trigger: 'blur' }
          ]
        }
      }
    },
    created() {
      this.getlist()
    },
    methods: {
      getlist(){
        const param = {
          "pageIndex":this.page,
          "pageSize":this.pageSize
        }
        Http.getEvaluations(param)
        .then( res => {
          this.tableData = res.data.data.rows;
          this.total = res.data.data.total
          console.log(res.data.data)
        })
      },
       timeFun(val) {
        return getTime(val)
      },
      srcFun(obj){
        if(obj.indexOf('http://') > -1){
          return obj
        } else{
          obj = 'http://odqiuyfsp.bkt.clouddn.com/'+obj
        }
        return obj
      },
      //选择 推荐
      handleSelectionChange(val) {
        this.$emit('checkFun',val)
        // this.checkFun(val)
      },
      checkFun(val) {  //选择方法
        this.$emit('checkFun',val)
      },
      stickFun(row) { //置顶方法
        this.$emit('putStick',row.row.dynamicId)
      },
      upStickFun(row){
         this.$emit('UpputStick',row.row.dynamicId)
      },
      passFun(row,i){ //审核方法
        this.$emit('passStick',row.row.dynamicId,i)
      },
      
      
      chageStatus(val) {
        let txt ='';
        val? txt ='开启' : txt = '关闭';
       
        this.$confirm(`确认 ${txt} 此文章吗 ？`)
        .then(_ => {
            console.log('aa')
        })
        .catch(_ => {
          console.log('bb')
          
        });
      
        console.log(val)
      },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      deletData(row) {
        
        this.$confirm(`确认删除此标签吗？`)
        .then(_ => {
          console.log(111111)
          Http.deleteKeyword(row)
          .then( res => {
            console.log(res)
            if( res.data.code == 200 ){
              this.$message.success('删除成功')
              this.getlist()         
            } else if(res.data.code == -1003) {
              this.$message.error(`请求失败原因：${res.data.message}`)
             
            }
          })
          .catch( error => {
            this.$message.error('服务器请求失败')
          })
        })
        .catch(_ => {
          //取消部分
          console.log('bb')
        });
      },
     
      
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        console.log(`当前页: ${val}`);
      },
     
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.editId ? this.editKeywordFun():this.addKeywordFun();
             this.editId ='';
             this.ruleForm2.keyword ='';
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      addKeywordFun(){
       
        Http.addKeyword({"keyword":this.ruleForm2.keyword})
        .then( res => {
          console.log(res)
          if( res.data.code == 200 ) { 
            this.$message.success('关键字添加成功')
            
            this.getlist()    
          } else if (res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            setTimeout(()=>{
              this.$router.push('/')
            },2000)
          } else {
            this.$message.error('关键字添加失败')              
          }
        })
        .catch( error => {
          this.$message.error('服务器请求失败')
          console.log(error)
        })
      },
      editKeywordFun(){
        Http.editKeyword({"keyword":this.ruleForm2.keyword,'id':this.editId})
        .then( res => {
          console.log(res)
          if( res.data.code == 200 ) { 
            this.$message.success('关键字修改成功')
            
            this.getlist()    
          } else if (res.data.code == -1003) {
            this.$message.error(`请求失败原因：${res.data.message}`)
            setTimeout(()=>{
              this.$router.push('/')
            },2000)
          } else {
            this.$message.error('关键字修改失败')              
          }
        })
        .catch( error => {
          this.$message.error('服务器请求失败')
          console.log(error)
        })
      },
      seachFun(){
        this.getlist()
      }
    }
  }
</script>
<style>
.dynamicBox{
  background: #fff;
  padding:10px;
  min-height: 500px
}
</style>
